package Items;

import java.awt.Graphics;
import java.util.ArrayList;

import Constructions.Construction;
import Constructions.Morgue;
import Constructions.Recycler;
import Main.SpaceGame;
import Tasks.DisposeOfItem;

public class ItemManager 
{
	public ArrayList<Item> itemList = new ArrayList<Item>();
	private SpaceGame main;
	
	public ItemManager(SpaceGame main)
	{
		this.main = main;
	}
	
	public void draw(Graphics g)
	{
		for(Item i:itemList)
		{
			i.draw(g);
		}
	}
	
	public void update()
	{
		for(Item i:itemList)
		{
			if(i.numUseable == 0 && i.beingPickedUp == false)
			{
				Construction disposer = null;
				if(!(i instanceof Corpse))
				{
					for(Construction c:main.constructionManager.constructionList)
					{
						if(c instanceof Recycler)
							disposer = c;
					}
					if(disposer != null)
					{
						main.taskManager.taskList.add(new DisposeOfItem(i, main, disposer));
						i.beingPickedUp = true;
					}
				}
				else
				{
					for(Construction c:main.constructionManager.constructionList)
					{
						if(c instanceof Morgue)
						{
							disposer = c;
						}
					}
					if(disposer != null)
					{
						main.taskManager.taskList.add(new DisposeOfItem(i, main, disposer));
						i.beingPickedUp = true;
					}
				}
			}
		}
	}
}
